//时间戳转换函数
export default function transformTime(timestamp){
    const now = new Date();
    const date = new Date(timestamp);

    const diffInMs = now.getTime() - timestamp;
    const diffInMinutes = diffInMs / (1000 * 60);

    // 如果是2分钟之内
    if (diffInMinutes <= 2) {
        return "刚刚";
    }

    const isSameDay =
        now.getFullYear() === date.getFullYear() &&
            now.getMonth() === date.getMonth() &&
            now.getDate() === date.getDate();

    // 如果是同一天
    if (isSameDay) {
        return date.toTimeString().slice(0, 5); // 格式化为 hh:mm
    }

    const isSameYear = now.getFullYear() === date.getFullYear();

    // 如果是同一年但不是同一天
    if (isSameYear) {
        return `${String(date.getMonth() + 1).padStart(2, "0")}:${String(
            date.getDate()
        ).padStart(2, "0")} ${date.toTimeString().slice(0, 5)}`;
    }

    // 如果不是同一年
    return `${date.getFullYear()}-${String(date.getMonth() + 1).padStart(
        2,
        "0"
    )}-${String(date.getDate()).padStart(2, "0")} ${date
        .toTimeString()
        .slice(0, 5)}`;
}